package com.wavehi.dao.impl;

import com.wavehi.dao.BaseDao;
import com.wavehi.dao.IUserDao;
import com.wavehi.pojo.User;

import java.util.List;

/**
 * @Author WaveHi
 * @Date 2/9/2021 下午 4:27
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class UserDaoImpl extends BaseDao implements IUserDao {
    @Override
    public void add(User user) {
        //获取sql语句
        String sql = "insert into t_user(u_username, u_password) values(?,?)";
        //添加
        update(sql,user.getUsername(),user.getPassword());
    }

    @Override
    public void update(User user) {
        //获取sql语句
        String sql = "update t_user set u_username=?,u_password=? where u_id=?";
        //更新
        update(sql,user.getUsername(),user.getPassword(),user.getId());

    }

    @Override
    public void delete(Integer id) {
        //获取sql语句
        String sql = "delete from t_user where u_id=?";
        //删除
        update(sql,id);
    }

    @Override
    public User select(String username) {
        //获取sql语句
        String sql = "select u_id id,u_username username,u_password password from t_user where u_username=?";
        //查询
        return selectForOne(User.class,sql,username);
    }

    @Override
    public List<User> list() {
        //获取sql语句
        String sql = "select u_id id,u_username username,u_password password from t_user";
        //查询
        return selectForList(User.class,sql);
    }
}
